//
//  PrivateCustomViewController.m
//  IconMaster
//
//  Created by mac on 2017/7/25.
//  Copyright © 2017年 yangweiwei. All rights reserved.
//

#import "PrivateCustomViewController.h"
#import "AlbumPhotoPicker.h"
#import "EditeNotAppViewController.h"
#import "EditeAppViewController.h"
#import "BeautifyViewController.h"
#import "StepMakeIconViewController.h"
@interface PrivateCustomViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *customeImgView;
@property (nonatomic, strong) NSDictionary *resultDict; 


@property (nonatomic, strong) NSString *isClickbtn;//点击的当前按钮
@property (weak, nonatomic) IBOutlet UIView *adView;
@property (weak, nonatomic) IBOutlet UIButton *telephoneBtn;
@property (weak, nonatomic) IBOutlet UIButton *appBtn;
@property (weak, nonatomic) IBOutlet UIButton *smsBtn;
@property (weak, nonatomic) IBOutlet UIButton *webBtn;
@property (weak, nonatomic) IBOutlet UIButton *emailBtn;

@end

@implementation PrivateCustomViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    if (self.themeImg) {
        self.customeImgView.image = self.themeImg;
    }
    self.customeImgView.layer.cornerRadius = 8.0;
    self.customeImgView.layer.masksToBounds = YES;
    [self setBarType];
    [self setAdView];
    // Do any additional setup after loading the view.
}
- (IBAction)photoBtnAction:(id)sender {
    AlbumPhotoPicker* picker = [[AlbumPhotoPicker alloc] init];
    picker.controller = self;
    picker.allowsEditing = true;
    picker.finishBlock = ^(AlbumPhotoPicker* photoPicker, NSDictionary* infoDict) {
        //        [self setIconImageWithPickerDict:infoDict];
        self.customeImgView.image = [infoDict objectForKey:UIImagePickerControllerEditedImage];
        [self dismissViewControllerAnimated:YES completion:nil];
    };
    [picker pickAlbum];
}
- (IBAction)cameraBtnAction:(id)sender {
    AlbumPhotoPicker* picker = [[AlbumPhotoPicker alloc] init];
    picker.controller = self;
    picker.allowsEditing = true;
    picker.finishBlock = ^(AlbumPhotoPicker* photoPicker, NSDictionary* infoDict) {
        //        [self setIconImageWithPickerDict:infoDict];
    self.customeImgView.image = [infoDict objectForKey:UIImagePickerControllerEditedImage];
        [self dismissViewControllerAnimated:YES completion:nil];
    };
    [picker pickCamera];
}
- (IBAction)okAppBtnAction:(id)sender {
    [UIView animateWithDuration:0.5 animations:^{
//        self.adView.frame = CGRectMake(0, KHeight, KWidth, 0);
        [self.view bringSubviewToFront:self.telephoneBtn];
        [self.view bringSubviewToFront:self.appBtn];
        [self.view bringSubviewToFront:self.smsBtn];
        [self.view bringSubviewToFront:self.webBtn];
        [self.view bringSubviewToFront:self.emailBtn];
        [self.view sendSubviewToBack:self.adView];
        self.adView.hidden = YES;
//        [self.adView removeFromSuperview];
    
    }];
}
- (IBAction)okNotAppBtnAction:(id)sender {
    [self performSegueWithIdentifier:@"notapp" sender:self];
}
- (IBAction)beautifiAction:(UIBarButtonItem *)sender {
//    [self performSegueWithIdentifier:@"beautify" sender:self];
    StepMakeIconViewController *setpVC = [[StepMakeIconViewController alloc] init];
    setpVC.font_image = self.customeImgView.image;
    setpVC.resultDictFont = self.resultDict;
    [self.navigationController pushViewController:setpVC animated:YES];
    setpVC.returnValueBlock = ^(NSDictionary *resultDict) {
        //sel
        self.customeImgView.image = [resultDict objectForKey:@"iconImage"];
        self.resultDict = resultDict;
    };
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    if ([segue.identifier isEqualToString:@"notapp"]) {
        
//        if ([self.isClickbtn isEqualToString:AppEdite]) {
//            //APP
//            
//        }else{
            //非APP
            EditeNotAppViewController *editeNotAppViewController = segue.destinationViewController;
            editeNotAppViewController.isFromClickStr = self.isClickbtn;
            editeNotAppViewController.customerImg = self.customeImgView.image;
 
//            [self showAdmobInController:self];
                         
//        }
    }if ([segue.identifier isEqualToString:@"beautify"]) {
        //
        BeautifyViewController *beautifyVC = segue.destinationViewController;
        beautifyVC.image = self.customeImgView.image;
    } else{
    
//        if ([self.isClickbtn isEqualToString:AppEdite]) {
            EditeAppViewController *editeAppVC = segue.destinationViewController;
            editeAppVC.isFromClickStr = self.isClickbtn;
            editeAppVC.customerImg = self.customeImgView.image;
//        }
//         [self showAdmobInController:self];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)telePhoneBtn:(id)sender {
    self.isClickbtn = Telephone;
    [self performSegueWithIdentifier:@"notapp" sender:self];
}
- (IBAction)appBtn:(id)sender {
    self.isClickbtn = AppEdite;
    [self performSegueWithIdentifier:@"app" sender:self];
}
- (IBAction)smsBtn:(id)sender {
    self.isClickbtn = SmsMessage;
    [self performSegueWithIdentifier:@"notapp" sender:self];
}
- (IBAction)webBtn:(id)sender {
    self.isClickbtn = WebSite;
    [self performSegueWithIdentifier:@"notapp" sender:self];
}
- (IBAction)emailBtn:(id)sender {
    self.isClickbtn = Email;
    [self performSegueWithIdentifier:@"notapp" sender:self];
}
- (void)setAdView{
    [self.view bringSubviewToFront:self.adView];
    GADBannerView* bannerView =
    [AdAndHint showBannerViewInController:self view:self.view frame:CGRectZero];
    CGRect bannerFrame = bannerView.frame;
    bannerFrame.origin.x = 0;
    bannerFrame.origin.y = KHeight -10-bannerFrame.size.height;
    bannerView.frame = bannerFrame;
    [self.adView addSubview:bannerView];
    bannerView.sd_layout.topEqualToView(self.adView).leftEqualToView(self.adView).rightEqualToView(self.adView).bottomEqualToView(self.adView);
    //    bannerView.autoresizingMask = segmentControl.autoresizingMask;
    
    [AdAndHint loadInterstitialIfNeed];
 
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
